package com.qc.bus.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.qc.bus.service.BusCustomerService;
import com.qc.sys.common.Constant;
import com.qc.sys.common.ResultObj;
import com.qc.bus.entity.BusCustomer;
import com.qc.bus.vo.CustomerVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * (BusCustomer)表控制层
 *
 * @author AltmanQccc
 * @since 2020-09-08 20:01:32
 */
@RestController
@RequestMapping("customer")
public class BusCustomerController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private BusCustomerService busCustomerService;

    /**
     * 查询并展示数据
     * */
    @GetMapping("loadAllCustomer")
    public Object loadAllCustomer(CustomerVo customerVo){
        return this.busCustomerService.queryAllCustomer(customerVo);
    }

    /**
     * 添加客户
     * */
    @PostMapping("addCustomer")
    public ResultObj addCustomer(BusCustomer customer){
        try {
            customer.setAvailable(Constant.USER_AVAILABLE_TRUE);
            this.busCustomerService.InsertCustomer(customer);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 修改客户
     * */
    @PostMapping("updateCustomer")
    public ResultObj updateCustomer(BusCustomer customer){
        try {
            this.busCustomerService.UpdateCustomer(customer);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 删除客户
     * */
    @PostMapping("deleteCustomer")
    public ResultObj deleteCustomer(Integer id){
        try {
            this.busCustomerService.removeById(id);
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 批量删除
     * */
    @PostMapping("batchDeleteCustomer")
    public ResultObj batchDeleteCustomer(Integer[] ids){
        return this.busCustomerService.batchDeleteCustomer(ids);
    }

    /**
     * 查询可用的客户
     * */
    @GetMapping("getAllAvailableCustomer")
    public Object getAllAvailableCustomer(){
        return this.busCustomerService.queryAllAvailableCustomer();
    }


}